package com.shop.loan.model;

import com.shop.loan.handler.UserBankDelHandler;
import com.shop.loan.model.vo.UserBankDelVo;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.expr.ExprBool;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_erupt.RowOperation;
import xyz.erupt.annotation.sub_field.*;
import xyz.erupt.annotation.sub_field.sub_edit.AttachmentType;
import xyz.erupt.annotation.sub_field.sub_edit.DateType;
import xyz.erupt.jpa.model.BaseModel;
import xyz.erupt.upms.handler.ViaMenuValueCtrl;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

@Getter
@Setter
@Entity
@Table(name = "s_user_bank")
@Erupt(
        name = "用户银行卡",
        power = @Power(viewDetails = false, edit = false, add = false, delete = false),
        filter = @Filter("UserBank.isDelete = false"),
        authVerify = false,
        rowOperation = {
                @RowOperation(
                        title = "解绑银行卡",
                        icon = "fa fa-trash-o text-red",
                        mode = RowOperation.Mode.SINGLE,
                        eruptClass = UserBankDelVo.class,
                        operationHandler = UserBankDelHandler.class,
                        show = @ExprBool(
                                exprHandler = ViaMenuValueCtrl.class,
                                params = "un_bank"  //权限标识，菜单类型为按钮，类型值为testBtn即可控制该按钮
                        )
                )
        }
)
@SQLDelete(sql = "update s_user_bank set is_delete = true, delete_time = now() where id = ?")
public class UserBank extends BaseModel {


    @Column(name = "user_id")
    private Long userId;


    @EruptField(
            views = @View(title = "卡号"),
            edit = @Edit(
                    title = "卡号"
            )
    )
    private String carNo;


    @EruptField(
            views = @View(title = "银行名称"),
            edit = @Edit(
                    title = "银行名称"
            )
    )
    private String bankName;


    @EruptField(
            views = @View(title = "预留手机号"),
            edit = @Edit(
                    title = "预留手机号"
            )
    )
    private String phone;

    @EruptField(
            views = @View(title = "银行卡图片", type = ViewType.IMAGE),
            edit = @Edit(title = "银行卡图片",
                    type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType(
                            type = AttachmentType.Type.IMAGE))
    )
    private String bankUrl;

    @EruptField(
            views = @View(title = "协议号"),
            edit = @Edit(
                    title = "协议号"
            )
    )
    private String protocol;

    @EruptField(
            views = @View(title = "绑定时间"),
            edit = @Edit(title = "绑定时间",
                    readonly = @Readonly,
                    dateType = @DateType(type = DateType.Type.DATE_TIME))
    )
    private Date createTime;


    private Boolean isDelete = false;

    private Date deleteTime;

}
